<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/7
 * Time: 15:39
 */

namespace app\api\controller;


use app\api\service\MainService;
use app\api\service\MecService;
use controller\BasicApi;
use think\Db;
use think\Request;

class index extends BasicApi {

    private $adSpotID = 11;

    public function index(){
        $res = MainService::loadAD($this->adSpotID);
        $res['bottom'] = MainService::loadAD(12);
        $res['recomdset'] = MecService::getRecomSet();
        $this->success("获取成功",$res);
    }
    public function acticle(){
        $art_id = $this->getParams('art_id');
        $res = MainService::getArticle($art_id);

        $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
        if($res){
            $res['content'] = str_replace('src="','src="'.$this->request->domain(),$res['content']);
            $this->success("获取成功",$res);
        }else{
            $this->error("参数错误");
        }
    }
    public function acticleList(){
        $category_id = $this->getParams('category_id');
        $res = MainService::getArticleType($category_id);
        if($res){
            $this->success("获取成功",$res);
        }else{
            $this->error("参数错误");
        }
    }
    private function getParams($param, $default="") {
//        return $this->request->post($param, $default);
        return $this->request->get($param, $default);
    }

    public function uploadimg() {
        $file = $this->request->file('file');

        if ($file) {
            $info = $file->move('static/upload/weixin/');
            if ($info) {
                $file = $info->getSaveName();
                $file = str_replace('\\','/',$file);
                return $this->request->domain()."/static/upload/weixin/".$file;
            }
        }
    }
    public function feedback(){
        $data['account_id'] = $this->getParams('account_id');
        $data['content'] = $this->getParams('content');
        $data['mobile'] = $this->getParams('mobile');
        $data['status'] = 1;
        $data['create_time'] = time();
        if(Db::name('feedback')->insertGetId($data)){
            $this->success('意见提交成功');
        }else{
            $this->error('意见提交失败');
        }
    }
    public function feed(){
        $data =  $this->request->param();
        $data['create_time'] = time();
        $data['isnew'] = 1;
        if(Db::name('feed')->insertGetId($data)){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }
    }
}